import java.io.*;

/**
 * @ClassName Demo04_TransformTest
 * @Description 练习：转换文件编码
 * 1.指定GBK编码的转换流，读取文本文件
 * 2.使用UTF-8编码的转换流，写出文本文件
 * @Author Li
 * @Date 2022/8/12 9:55
 * @ModifyDate 2022/8/12 9:55
 * @Version 1.0
 */
public class Demo04_TransformTest {
    public static void main(String[] args) throws IOException {
        // 定义文件路径
        String srcFile = "src/part10/ch02_TransformStream/File_gbk.txt";
        String destFile = "src/part10/ch02_TransformStream/File_utf8.txt";
        // 创建流对象
        InputStreamReader isr = new InputStreamReader(new FileInputStream(srcFile), "GBK");
        OutputStreamWriter osw = new OutputStreamWriter(new FileOutputStream(destFile));
        // 读写数据
        char[] chars = new char[1024];
        int len;
        while ((len = isr.read(chars)) != -1) {
            osw.write(chars, 0, len);
        }
        // 释放资源
        osw.close();
        isr.close();
    }
}
